package com.solve.controller;

import com.github.pagehelper.PageInfo;
import com.solve.entity.ResourceInfoUser;
import com.solve.entity.ResourceInfoUserExtend;
import com.solve.entity.base.BaseResponse;
import com.solve.service.impl.ResourceInfoUseServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/resourceInfoUser")
public class ResourceInfoUserControlle {

    @Resource
    private ResourceInfoUseServiceImpl resourceInfoUseService;

    @PostMapping("/saveResourceInfo")
    public BaseResponse saveResourceInfo(@RequestBody ResourceInfoUser resourceInfoUser){
        String uuid = resourceInfoUseService.saveResourceInfoReturnId(resourceInfoUser);
        return new BaseResponse(true,"保存成功",uuid);
    }
    @PostMapping("/selectResourceInfoList")
    public BaseResponse selectResourceInfoList(@RequestBody(required=false) ResourceInfoUser resourceInfoUser){
        PageInfo pageInfo = resourceInfoUseService.getResourceInfoUserByPageInfo(resourceInfoUser);
        return new BaseResponse(true,"保存成功",pageInfo);
    }

    @GetMapping("/getResourceInfoUserInfo")
    public BaseResponse getResourceInfoUserInfo(ResourceInfoUser resourceInfoUser){
        ResourceInfoUserExtend resourceInfoUserdb =  resourceInfoUseService.getResourceInfoUserInfo(resourceInfoUser);
        return new BaseResponse(true,"保存成功",resourceInfoUserdb);
    }

    @GetMapping("exchangeResource")
    public BaseResponse exchangeResource( ResourceInfoUser resourceInfoUser) throws Exception{
         resourceInfoUseService.exchangeResource(resourceInfoUser);
         return new BaseResponse(true,"兑换成功！",null);
    }

    @GetMapping("/getResourceInfoUserDetailInfo")
    public  BaseResponse getResourceInfoUserDetailInfo(ResourceInfoUser resourceInfoUser){
        resourceInfoUser = resourceInfoUseService.getResourceInfoUserDetailInfo(resourceInfoUser);
        return new BaseResponse(true,"兑换成功！",resourceInfoUser);
    }
}
